<template>
	<div class="app-container">
		<jk-operation-card ref="box1" class="margin-bottom-10">
			<!--<div class="flex-between-center-wrap">
				<div class="flex-start-center-wrap">
				</div>
				<div class="flex-end-center-wrap">
					<jk-search-input v-model="searchParams.empName" placeholder="人员名称" size="small" class="search-bar-item-size2 margin-5-0 item-gap" clearable @on-enter="onSearchBtn" />
					<jk-search-button @click="onSearchBtn"></jk-search-button>
				</div>
			</div>-->
			<div class="total-box">
				<div
					v-for="(item, index) in totalList"
					:key="index"
					class="total-item"
					:style="{ borderColor: item.color }"
				>
					<div class="total-item-val">{{ item.val }}</div>
					<div class="total-item-title">{{ item.name }}({{ item.unit }})</div>
				</div>
				<el-button size="small" icon="el-icon-refresh" type="primary" circle style="position: absolute;right: 0px;top: 50%;margin-top: -16px;" @click="getListRequest"></el-button>
			</div>
		</jk-operation-card>

		<jk-card>
			<jk-table ref="jkTable" :cell-style="cellStyle" :header-cell-style="cellStyle" :loading="tableLoading" :data="tableData" :height="tableHeight + 20">
				<vxe-column
					v-for="(item, index) in tableColumnList"
					:key="index"
					:title="item.title"
					:align="item.align"
					:field="item.keyName"
					:sortable="item.sortable"
					:fixed="item.fixed ? item.fixed : ''"
					:min-width="item.minWidth"
					:width="item.width"
				>
					<template slot-scope="scope">
						<xs-report-state-bar v-if="item.keyName === 'CurMachineStatus'" :status="scope.row.CurMachineStatus"></xs-report-state-bar>
						<span v-else-if="item.keyName === 'ifBase'">{{ scope.row.ifBase ? '是' : '否' }}</span>
						<span v-else>{{ scope.row[item.keyName] }}</span>
					</template>
				</vxe-column>
			</jk-table>
			<!--<jk-table ref="jkTable" :loading="tableLoading" :data="tableData" :height="tableHeight / 2">
				<vxe-column
					v-for="(item, index) in tableColumnList2"
					:key="index"
					:title="item.title"
					:align="item.align"
					:field="item.keyName"
					:sortable="item.sortable"
					:fixed="item.fixed ? item.fixed : ''"
					:min-width="item.minWidth"
					:width="item.width"
				>
					<template slot-scope="scope">
						<xs-report-state-bar v-if="item.keyName === 'CurMachineStatus'" :status="scope.row.CurMachineStatus"></xs-report-state-bar>
						<span v-else-if="item.keyName === 'ifBase'">{{ scope.row.ifBase ? '是' : '否' }}</span>
						<span v-else>{{ scope.row[item.keyName] }}</span>
					</template>
				</vxe-column>
			</jk-table>-->

			<!-- 分页组件 -->
			<!--<footer ref="box2" class="flex-end-center margin-top-10">
				<jk-page
					:page-index="searchParams.pageNo"
					:page-sizes="searchParams.pageSizes"
					:page-size="searchParams.pageSize"
					:total="totalCount"
					@on-change="onPageChange"
				/>
			</footer>-->
		</jk-card>
	</div>
</template>

<script>
    import { auditStateList } from '@/utils/jk/status-option-list';
    import calHeight from '/src/mixins/cal-table-height';
    import { firstCharacterToLowerCase, pageConfig } from '/src/utils/jk/jk-tool';
    import getMenuColumn from '../../../mixins/getMenuColumn';
    import handlerCache from '../../../mixins/handler-cache';
    import { spinReportProductionStatementGetList } from '../../../api/production/reports';
    import xsReportStateBar from './xs-report-state-bar';
    import { systemUserColumnConfigGet } from '../../../api/system/column-config';
    export default {
        name: 'XsProductionReport',
        components: {
            xsReportStateBar
        },
        mixins: [calHeight, getMenuColumn, handlerCache],
        data() {
            return {
                prefix: 'production:productUseCommunication',
                apiItem: {
                    'page': spinReportProductionStatementGetList
                },
                totalList: [
                    { key: 'KG', name: '总产量', val: 1212, unit: '千克', color: '#2d8cf0' },
                    { key: 'EffGlobal', name: '总效率', val: 1212, unit: '%', color: '#19be6b' },
                    { key: 'DOFF', name: '落纱次数', val: 1212, unit: '次', color: '#ff9900' },
                    { key: 'SSTOP', name: '停机次数', val: 1212, unit: '次', color: '#ed4014' },
                    { key: 'TotalBreaks', name: '断头次数', val: 1212, unit: '次', color: 'rgb(55, 214, 226)' },
                    { key: 'KWH', name: '总耗电量', val: 1212, unit: '千瓦时', color: 'rgb(161, 92, 253)' }
                ],
                tableColumnList2: [],
                importDialogState: false,
                auditStateList: auditStateList,
                dataId: null,
                tableLoading: true,
                exportLoading: false,
                tableData: [],
                searchParams: {
                    pageNo: pageConfig.pageNo,
                    pageSize: pageConfig.pageSize,
                    empName: null,
                    typeId: null,
                    auditState: null,
                    ifTest: process.env.VUE_APP_MODE === 'development'
                }
            };
        },
        methods: {
            cellStyle({ column }) {
                if (column.field === 'CurBrokenSpindles') {
                    return {
                        boxShadow: 'inset 0 0 0px 0.5px rgb(145, 213, 255)',
                        backgroundImage: 'none',
                        background: 'rgb(230, 247, 255)',
                        color: 'rgb(24, 144, 255)'
                    };
                } else if (column.field === 'EffQty') {
                    return {
                        boxShadow: 'inset 0 0 0px 0.5px rgb(211, 173, 247)',
                        backgroundImage: 'none',
                        background: 'rgb(249, 240, 255)',
                        color: 'rgb(114, 46, 209)'
                    };
                } else if (column.field === 'KG') {
                    return {
                        boxShadow: 'inset 0 0 0px 0.5px rgb(236, 165, 165)',
                        backgroundImage: 'none',
                        background: 'rgb(254, 240, 240)',
                        color: 'rgb(245, 108, 108)'
                    };
                } else {
                    return {};
                }
            },
            onVisibleChangeOfImportDialog(e) {
                this.importDialogState = e;
            },
            onFinishBtnOfImportDialog() {
                this.importDialogState = false;
                this.getListRequest();
            },
            onPageChange(pageIndex, pageSize) {
                this.searchParams.pageNo = pageIndex;
                this.searchParams.pageSize = pageSize;
                this.getListRequest();
            },
            onDetailBtn(e) {
                this.dataId = e.id;
            },
            /** 查询列表 */
            getListRequest() {
                this.tableLoading = true;
                this.apiItem.page(this.searchParams).then(res => {
                    this.tableLoading = false;
                    if (res.data.status === 200) {
                        const resData = res.data.res || {};
                        this.tableData = resData.machineList;
                        this.totalCount = resData.count;
                        this.totalList.forEach(x => {
                            x.val = resData[x.key] ? parseInt(resData[x.key] * 100) / 100 : 0;
                        });
                    }
                });
            },
            /** 搜索按钮操作 */
            onSearchBtn() {
                this.searchParams.pageNo = 1;
                this.totalCount = 1;
                this.getListRequest();
            },
            /** 删除按钮操作 */
            onDeleteBtn(row) {
                this.apiItem.delete({ id: row.id }).then((res) => {
                    if (res.data.status === 200) {
                        this.getListRequest();
                        this.$tipsBar(this, 'delete');
                    }
                }).catch(() => {});
            },
            clearCacheMethod() {
                // Object.assign(this.$data, this.$options.data());
                this.$nextTick(() => {
                    this.getDependentData();
                });
            },
            getMenuColumnListRequest() {
                return systemUserColumnConfigGet({ path: firstCharacterToLowerCase(this.$route.name), filterShow: true }).then(res => {
                    if (res.data.status === 200) {
                        this.tableColumnList = res.data.res.columnConfigList && res.data.res.columnConfigList.length ? res.data.res.columnConfigList[0].itemList : [];
                        this.tableColumnList2 = res.data.res.columnConfigList && res.data.res.columnConfigList.length ? res.data.res.columnConfigList[1].itemList : [];
                    }
                });
            },
            async getDependentData() {
                await this.getMenuColumnListRequest();
                await this.getListRequest();
            }
        },
        mounted() {
            this.getDependentData();
        }
    };
</script>
<style scoped lang="scss">
    .total-box {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 8px 12px;
        position: relative;
        .total-item {
            width: 136px;
            height: 64px;
            box-shadow: 1px 2px 3px 1px #c5c8ce;
            border-radius: 6px;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            margin: 0 8px;
            padding: 4px 12px;
            border-bottom: 3px solid #fff;
            .total-item-val {
                font-size: 18px;
                color: #515a6e;
                font-weight: 700;
            }
            .total-item-title {
                font-size: 13px;
                color: #515a6e;
            }
        }
    }
</style>
